package cn.xx.user.controller;

import cn.xx.basic.util.AjaxResult;
import cn.xx.user.domain.User;
import cn.xx.user.dto.UserDto;
import cn.xx.user.service.IUserService;
import cn.xx.user.service.IUserService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user2")
public class UserController2 {

    @Autowired
    private IUserService2 userService2;

    @PostMapping("/checkPhone")
    public AjaxResult checkPhone (@RequestBody User user) {
        try {
            // 调用service方法传入user.getPhong
            userService2.checkPhone(user.getPhone());
            return new AjaxResult().me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg(e.getMessage()).setSuccess(false);
        }
    }

    @PostMapping("/register")
    public AjaxResult register (@RequestBody UserDto dto) {
        try {
            userService2.register(dto);
            return new AjaxResult().me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg(e.getMessage()).setSuccess(false);
        }
    }


}
